package cloudoer.su.action;

import cloudoer.su.base.impl.BaseAction;
import cloudoer.su.entity.Person;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.List;

@Controller
@Scope("prototype")
public class PersonAction extends BaseAction {
    public String getAll() throws IOException {
        String q = ServletActionContext.getRequest().getParameter("q");
        List<Person> list = personService.getAll(q);
        ajaxJson(list, new String[]{"classes","dormitory","classCommittees"});
        return null;
    }

    public String getByPage() throws IOException {
        int pageNo = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));
        int pageSize = Integer.parseInt(ServletActionContext.getRequest().getParameter("rows"));
        List<Person> list = personService.getByPage(pageNo, pageSize);
        ajaxDataGrid(personService.getCount(),list, new String[]{"classes","dormitory","classCommittees"});
        return null;
    }

    public String getById () throws IOException {
        String id = ServletActionContext.getRequest().getParameter("id");
        Person person = personService.getById(id);
        ajaxJson(person, new String[]{"classes","dormitory","classCommittees"});
        return null;
    }

    public String getByNumber() throws IOException {
        String number = ServletActionContext.getRequest().getParameter("number");
        Person person = personService.getByNumber(number);
        ajaxJson(person, new String[]{"classes","dormitory","classCommittees"});
        return null;
    }
}
